import { CustomerService } from './../../../../@core/services/customer/customer.service';
import { Component, Input } from '@angular/core';
import { CascaderItem } from 'ng-devui';
@Component({
  selector: 'app-add-customer-types',
  templateUrl: './add-customer-types.component.html',
  styleUrls: ['./add-customer-types.component.scss']
})
export class AddCustomerTypesComponent {
  @Input() data: any
  form: any = {
    customerClassId: null,
    customerClassName: "",
    note: "",
    parentCustomerClassId: null,
    subCustomerClasses:[]
  }
  options = []
  pathPids: any = []
  constructor(private CustomerService:CustomerService) { }
  ngOnInit(): void {
    console.log(this.data)
      this.options = this.convertToCascaderItem(this.data.options)
      if(this.data.pathPids){
        this.form.parentCustomerClassId = this.data.pathPids[this.data.pathPids.length-1]
      }
  }
  convertToCascaderItem(data: any[]): CascaderItem[] {
    return data.map(item => {
      let cascaderItem: CascaderItem = {
        label: item.customerClassName,
        value: item.customerClassId,
      };
      if (item.subCustomerClasses) {
        cascaderItem.children = this.convertToCascaderItem(item.subCustomerClasses);
      }
      return cascaderItem;
    });
  }//转换数据格式为华为库练级菜单的数据格式
  ngModelChange() {
    this.form.parentCustomerClassId = this.pathPids[this.pathPids.length - 1]
  }
}
